<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发布人id">
            <el-input v-model="form.userId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="标题">
            <el-input v-model="form.title" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="租金/月">
            <el-input v-model="form.renet" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="付款方式">
            <el-input v-model="form.payType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="房屋面积">
            <el-input v-model="form.area" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="房型">
            <el-input v-model="form.houseType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="房屋朝向">
            <el-input v-model="form.toward" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="楼层">
            <el-input v-model="form.floor" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否有电梯">
            <el-input v-model="form.hasLift" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="1毛坯房；2简装修；3精装修">
                未设置字典，请手动设置 Radio
          </el-form-item>
          <el-form-item label="地址">
            <el-input v-model="form.address" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态：-1待提交，草稿，0待审核；1审核通过；2审核失败;3已过期">
            <el-input v-model="form.status" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="生效时间">
            <el-input v-model="form.startTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结束时间">
            <el-input v-model="form.endTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="联系电话">
            <el-input v-model="form.tel" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="userId" label="发布人id" />
        <el-table-column prop="title" label="标题" />
        <el-table-column prop="renet" label="租金/月" />
        <el-table-column prop="payType" label="付款方式" />
        <el-table-column prop="area" label="房屋面积" />
        <el-table-column prop="houseType" label="房型" />
        <el-table-column prop="toward" label="房屋朝向" />
        <el-table-column prop="floor" label="楼层" />
        <el-table-column prop="hasLift" label="是否有电梯" />
        <el-table-column prop="decoration" label="1毛坯房；2简装修；3精装修" />
        <el-table-column prop="address" label="地址" />
        <el-table-column prop="status" label="状态：-1待提交，草稿，0待审核；1审核通过；2审核失败;3已过期" />
        <el-table-column prop="startTime" label="生效时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="结束时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="tel" label="联系电话" />
        <el-table-column v-permission="['admin','rental:edit','rental:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudRental from '@/api/rental'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, userId: null, title: null, renet: null, payType: null, area: null, houseType: null, toward: null, floor: null, hasLift: null, decoration: null, address: null, createTime: null, updateTime: null, createBy: null, updateBy: null, status: null, startTime: null, endTime: null, tel: null }
export default {
  name: 'Rental',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '出租', url: 'api/rental', sort: 'id,desc', crudMethod: { ...crudRental }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'rental:add'],
        edit: ['admin', 'rental:edit'],
        del: ['admin', 'rental:del']
      },
      rules: {
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
